package cn.com.njws.base;import it.sauronsoftware.jave.AudioAttributes;import it.sauronsoftware.jave.Encoder;import it.sauronsoftware.jave.EncoderException;import it.sauronsoftware.jave.EncodingAttributes;import it.sauronsoftware.jave.InputFormatException;import java.io.File;import cn.com.cola.controller.annotation.Action;@Action("/test")public class testAction { public static void main(String[] args) throws Exception { String path1 = "E:\\f539f6a2-7dba-4bbb-901e-94a28317143f__audio.amr"; String path2 = "E:\\f539f6a2-7dba-4bbb-901e-94a28317143f__audio.mp3"; changeToMp3(path1, path2); } public static void changeToMp3(String sourcePath, String targetPath) { File source = new File(sourcePath); File target = new File(targetPath); AudioAttributes audio = new AudioAttributes(); Encoder encoder = new Encoder(); audio.setCodec("libmp3lame"); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mp3"); attrs.setAudioAttributes(audio); try { encoder.encode(source, target, attrs); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InputFormatException e) { e.printStackTrace(); } catch (EncoderException e) { e.printStackTrace(); } } }
评论